﻿using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
using DG.Tweening;

public static class EffMgr 
{
    public const string Tag_Explode = "Eff_Circle";

    public static async Task<GameObject> CreateEffAsync(string tag)
    {
        GameObject prefab = await Addressables.LoadAssetAsync<GameObject>(tag).Task;

        if (prefab == null)
        {
            Debug.LogError($"加载特效预制失败 tag:{tag}");
            return null;
        }
        else
            return MonoBehaviour.Instantiate(prefab);
    }

    public static async void CreateExplodeEffAsync(Vector3 pos, Battle.ST_RangeData rangeData,Color color)
    {
        GameObject eff = await CreateEffAsync(Tag_Explode);

        if (eff != null)
        {
            eff.GetComponentInChildren<SpriteRenderer>().color = color;

            eff.transform.position = pos;
            eff.transform.localScale = Vector3.zero;
            eff.transform.DOScale(Vector3.one * (float)rangeData.dRadius*2f, 0.2f).OnComplete(()=>
            {
                MonoBehaviour.Destroy(eff);
            });
        }
    }
}
